package org.example.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 *
 */

//spring配置类
//@Configuration

//读取resources里面的jdbc.properties文件
@PropertySource("classpath:jdbc.properties")
public class JdbcConfig {

    //专题：简单类型值的注入 8大基本+String+List+Array
    @Value("${jdbc.driver}")
    String drive;
    @Value("${jdbc.url}")
    String url;
    @Value("${jdbc.username}")
    String username;
    @Value("${jdbc.password}")
    String password;

    // 将数据源对象，配置完毕后，交给spring管理
    @Bean
    public DataSource getSource(){
        DruidDataSource dds = new DruidDataSource();
        dds.setDriverClassName(drive);
        dds.setUrl(url);
        dds.setUsername(username);
        dds.setPassword(password);
        return dds;
    }


}





























